package vn.bk.hotel.dialog;

import vn.bk.hotel.R;
import vn.bk.hotel.ViewMap;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class DialogMapView {
    private ViewMap mContext;

    public static final int NORMAL = 0;
    public static final int SATELLITE = 1;
    public static int typeMap = NORMAL;
    private AlertDialog.Builder dialog;

    public DialogMapView(ViewMap context) {
	this.mContext = context;
	View view = View
		.inflate(mContext, R.layout.dialog_choose_mapview, null);
	dialog = new AlertDialog.Builder(mContext);
	final RadioGroup group = (RadioGroup) view
		.findViewById(R.id.group_view);

	RadioButton normal = (RadioButton) view.findViewById(R.id.normal);
	RadioButton satellite = (RadioButton) view.findViewById(R.id.satellite);
	if (typeMap == NORMAL) {
	    normal.setChecked(true);
	} else {
	    satellite.setChecked(true);
	}

	dialog.setTitle(context.getString(R.string.choose_map));
	dialog.setView(view);
	dialog.setNegativeButton("Cancel", new OnClickListener() {

	    @Override
	    public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		dialog.dismiss();
	    }
	});

	dialog.setPositiveButton("OK", new OnClickListener() {

	    @Override
	    public void onClick(DialogInterface dialog, int which) {

		switch (group.getCheckedRadioButtonId()) {
		case R.id.normal:
		    typeMap = NORMAL;
		    break;
		case R.id.satellite:
		    typeMap = SATELLITE;
		    break;

		default:
		    typeMap = NORMAL;
		    break;
		}
		mContext.changeMapView(typeMap);

	    }
	});
    }

    public void show() {

	dialog.show();
    }
}
